home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / OvalShp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  7.2 KB  |  280 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                OvalShp.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef OVALSHP_H
  23. #include "OvalShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. #ifndef FWGRUTIL_H
  107. #include "FWGrUtil.h"
  108. #endif
  109.  
  110. // ----- Foundation Includes -----
  111.  
  112. #ifndef FWSTREAM_H
  113. #include "FWStream.h"
  114. #endif
  115.  
  116. // ----- OpenDoc Includes -----
  117.  
  118. #ifndef SOM_ODTransform_xh
  119. #include <Trnsform.xh>
  120. #endif
  121.  
  122. //========================================================================================
  123. // Runtime Information
  124. //========================================================================================
  125.  
  126. #ifdef FW_BUILD_MAC
  127. #pragma segment odfdrawshapes
  128. #endif
  129.  
  130. //========================================================================================
  131. // RunTime Info
  132. //========================================================================================
  133.  
  134. FW_DEFINE_AUTO(COvalShape)
  135. FW_DEFINE_CLASS_M1(COvalShape, CBoundedShape)
  136.  
  137. const FW_ClassTypeConstant LOvalShape = FW_TYPE_CONSTANT('s','h','o','v');
  138. FW_REGISTER_ARCHIVABLE_CLASS(LOvalShape, COvalShape, COvalShape::Read, 0, 0, CBaseShape::Write)
  139.  
  140. //========================================================================================
  141. // class COvalShape
  142. //========================================================================================
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // COvalShape::COvalShape
  146. //----------------------------------------------------------------------------------------
  147.  
  148. COvalShape::COvalShape(CDrawPart* drawPart):
  149.     CBoundedShape(drawPart, kOvalShape, kFrameOnly)
  150. {
  151.     FW_END_CONSTRUCTOR
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. // COvalShape::COvalShape
  156. //----------------------------------------------------------------------------------------
  157.  
  158. COvalShape::COvalShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
  159.     CBoundedShape(drawPart, archive)
  160. {    
  161.     FW_END_CONSTRUCTOR
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. // COvalShape::~COvalShape
  166. //----------------------------------------------------------------------------------------
  167.  
  168. COvalShape::~COvalShape()
  169. {
  170.     FW_START_DESTRUCTOR
  171. }
  172.  
  173. //----------------------------------------------------------------------------------------
  174. // COvalShape::OutlineShape
  175. //----------------------------------------------------------------------------------------
  176.  
  177. void COvalShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
  178. {
  179.     FW_CRect bounds(rect);
  180.     AdjustRectForPenSize(bounds, style.GetPenSize());
  181.     FW_COvalShape::RenderOval(gc,
  182.                               bounds,
  183.                               FW_kFrame,
  184.                               ink, style);
  185. }
  186.  
  187. //----------------------------------------------------------------------------------------
  188. // COvalShape::RenderShape
  189. //----------------------------------------------------------------------------------------
  190.  
  191. void COvalShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  192. {
  193. FW_UNUSED(ev);
  194. FW_UNUSED(facet);
  195.     FW_CRect rect = GetRectGeometry();
  196.     AdjustRectForPenSize(rect, GetPenSize());
  197.     
  198.     if (HasFillStyle())
  199.         FW_COvalShape::RenderOval(gc, rect, FW_kFill, fFillInk, fFillStyle);
  200.     
  201.     if (HasFrameStyle())
  202.         FW_COvalShape::RenderOval(gc, rect, FW_kFrame, fFrameInk, fFrameStyle);
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. // COvalShape::HitTest
  207. //----------------------------------------------------------------------------------------
  208.  
  209. FW_Boolean COvalShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  210. {    
  211.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  212.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  213.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  214.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  215.  
  216.     FW_CRect bounds = GetRectGeometry();
  217.     AdjustRectForPenSize(bounds, GetPenSize());
  218.  
  219.     FW_COvalShape ovalShape(bounds, HasFillStyle() ? FW_kFill : FW_kFrame);
  220.     return ovalShape.HitTest(gc, mouse, FW_IntToFixed(2));
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. // COvalShape::CalcClipShape
  225. //----------------------------------------------------------------------------------------
  226.  
  227. ODShape* COvalShape::CalcClipShape(Environment* ev)
  228. {
  229.     FW_CRect bounds = GetRectGeometry();
  230.     AdjustRectForPenSize(bounds, GetPenSize());
  231.     
  232.     FW_CAcquiredODShape clipShape = ::FW_CreateOvalODShape(ev, bounds);
  233.     
  234.     if (FrameOnly())
  235.     {
  236.         bounds.Inset(GetPenSize(), GetPenSize());
  237.         FW_CAcquiredODShape ovalShape = ::FW_CreateOvalODShape(ev, bounds);
  238.         clipShape->Subtract(ev, ovalShape);
  239.     }
  240.     
  241.     return clipShape.Orphan();
  242. }
  243.  
  244. //----------------------------------------------------------------------------------------
  245. // COvalShape::CreateShapeOutline
  246. //----------------------------------------------------------------------------------------
  247.  
  248. ODShape* COvalShape::CreateShapeOutline(Environment *ev)
  249. {
  250.     FW_CRect bounds = GetRectGeometry();
  251.     AdjustRectForPenSize(bounds, GetPenSize());
  252.     
  253.     FW_CAcquiredODShape dragRgn = ::FW_CreateOvalODShape(ev, bounds);
  254.     
  255.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  256.     
  257.     return dragRgn.Orphan();
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. // COvalShape::Read
  262. //----------------------------------------------------------------------------------------
  263.  
  264. void* COvalShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  265. {
  266. FW_UNUSED(type);
  267.     // [HLX] This is a hack until I can register object with the archiver
  268.     CDrawReadableStream *drawArchive = (CDrawReadableStream*)&stream;
  269.     return FW_NEW(COvalShape, (drawArchive->GetDrawPart(), stream));
  270. }
  271.  
  272. //----------------------------------------------------------------------------------------
  273. // COvalShape::GetObjectClass
  274. //----------------------------------------------------------------------------------------
  275.  
  276. ODDescType COvalShape::GetObjectClass() const
  277. {
  278.     return cOval;
  279. }
  280.